import { Inject, Injectable } from '@nestjs/common';
import { QueryOpenIdDto } from './dto/query-openId.dto';
import { HttpService } from '@nestjs/axios';
import { ConfigService } from '@nestjs/config';
import { firstValueFrom } from 'rxjs';

@Injectable()
export class ObpService {
  @Inject(ConfigService)
  private configService: ConfigService;

  constructor(private readonly httpService: HttpService) {}
  async queryOpenIdByUserId(queryDto: QueryOpenIdDto) {
    const { userId } = queryDto;
    const observable = this.httpService.get(
      `${this.configService.get('obp.api.origin')}/umsAdmin/get/${userId}`,
    );
    const res = await firstValueFrom(observable);
    console.log('res', res.data);
    const { success, content } = res.data;
    if (success) {
      return content;
    }
    return res.data;
  }
}
